package com.traveldream.backend.managed_beans;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.traveldream.entities.Place;
import com.traveldream.entity_managers.PlaceManager;

@ManagedBean(name="placeBackend")
@SessionScoped
public class PlaceBean {
	

	public static final String WEB_PATH = "/backend/place/";
	
	
	@EJB
	private PlaceManager pm; // instance of place manager
	
	private List<Place> list;
	private Place current;
	
	public PlaceBean(){
		current = new Place();
		list = null ;
	}
	
	public String createAction(){
		current = new Place();
		
		return WEB_PATH+"new";
	}
	
	public String editAction(Place p){
		current = p;
		
	
		return WEB_PATH+"edit";
	}
	
	public String create(){
		
		pm.create(current);
		this.list = null;
		return WEB_PATH+"list";
	}
	
	public String update(){
		
		pm.update(current);
		this.list = null;
		return WEB_PATH+"list";
	}

	public List<Place> getList() {
		if( list == null)
			list = pm.findAll();
		return list;
	}

	public void setList(List<Place> list) {
		this.list = list;
	}

	public Place getCurrent() {
		return current;
	}

	public void setCurrent(Place current) {
		this.current = current;
	}
	
	
}
